
package tests.laurens.lexchattest;

import java.util.ArrayList;
import java.util.Date;


public class ChatSystem {


	// Every new message gets an unique ID
	private int lastMessageID = 0;

	public int getLastMessageID() {
		return ++lastMessageID;
	}

	public ArrayList<message> allMessages = new ArrayList<message>();

	public void addToMessageQue(message m) {
		allMessages.add(m);
	}

	public ArrayList<message> getAllMessages() {
		return allMessages;
	}
	public ArrayList<message> getNewMessages(int lastknownMessageID) {
		// Create new arraylist for new message items
		ArrayList<message> newMessages = new ArrayList<message>();

		for(int i = 0; i < allMessages.size(); i++) {

			if(allMessages.get(i).getMessageID() > lastknownMessageID) {
				newMessages.add(allMessages.get(i));

			}
		}
		return newMessages;
	}
}


class message {

	private int messageID;
	private Date timestamp;
	private String username;
	private String message;

	public message(int _messageID, String _username, String _message) {
		setMessageID(_messageID);
		setTimestamp(new Date());
		setUsername(_username);
		setMessage(_message);
	}

	public void setMessageID(int messageID) {
		this.messageID = messageID;
	}

	public int getMessageID() {
		return messageID;
	}

	public void setTimestamp(Date timestamp) {
		this.timestamp = timestamp;
	}

	public Date getTimestamp() {
		return timestamp;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getUsername() {
		return username;
	}
	public void setMessage(String message) {
		this.message = message;
	}

	public String getMessage() {
		return message;
	}
}
